package com.heima.homeservicemanagementsystem.module;

import lombok.AllArgsConstructor;
import lombok.Data;

import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Description
 * @Author susu
 * @Date 2024/11/24
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private int code;
    private String message;
    private T result;

    public Result(String message, T result) {
        this.message = message;
        this.result = result;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> Result<T> success() {
        return new Result<>(200, "成功！");
    }

    public static <T> Result<T> success(T result) {
        return new Result<>(200, "成功", result);
    }


    public static <T> Result<T> success(String message, T result) {
        return new Result<>(200, message, result);
    }

    public static <T> Result<T> error() {
        return new Result<>(500, "失败");
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(500, message);
    }

    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message);
    }

    public static <T> Result<T> error(int code, String message, T result) {
        return new Result<>(code, message, result);
    }
}
